package com.culturalCenter.dataCenter.mapper.site;

import com.culturalCenter.dataCenter.entity.site.SiteBooking;
import com.culturalCenter.dataCenter.entity.site.SiteRuleTime;
import com.culturalCenter.dataCenter.mapper.base.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SiteRuleTimeMapper extends BaseMapper<SiteRuleTime> {

    /**
     * 批量插入数据
     *
     * @param collect
     */
    void insertBatch(List<SiteRuleTime> collect);

    /**
     * 根据时间规则查询排期
     *
     * @param date
     * @param dayOfWeek
     *
     * @return
     */
    @Select("SELECT s.refId siteId, STR_TO_DATE(CONCAT(#{date},' ', SUBSTRING_INDEX(`time`,'-',1)), '%Y-%m-%d %H:%i') beginTime, STR_TO_DATE(CONCAT(#{date},' ',SUBSTRING_INDEX(`time`,'-',-1)),'%Y-%m-%d %H:%i') endTime " +
            "FROM cdc_site_rule_time srt " +
            "INNER JOIN cdc_site s ON srt.ruleId = s.ruleId WHERE srt.cycle = #{dayOfWeek}")
    List<SiteBooking> selectSiteBooking(@Param("date") String date, @Param("dayOfWeek") String dayOfWeek);

    @Select("SELECT s.refId siteId, STR_TO_DATE(CONCAT(#{date},' ', SUBSTRING_INDEX(`time`,'-',1)), '%Y-%m-%d %H:%i') beginTime, STR_TO_DATE(CONCAT(#{date},' ',SUBSTRING_INDEX(`time`,'-',-1)),'%Y-%m-%d %H:%i') endTime " +
            "FROM cdc_site_rule_time srt " +
            "INNER JOIN cdc_site s ON srt.ruleId = s.ruleId WHERE srt.range = 'ALL'")
    List<SiteBooking> selectSiteBookingByRange(String toString);

}
